package com.niu.crm.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.niu.crm.dao.mapper.ExamMapper;
import com.niu.crm.model.Exam;
import com.niu.crm.model.User;
import com.niu.crm.service.BaseService;
import com.niu.crm.service.ExamService;

@Service
public class ExamServiceImpl extends BaseService implements ExamService {

	@Autowired
	private ExamMapper examMapper;
	
	@Override
	public Exam load(Long id) {
		return examMapper.selectByPrimaryKey(id);
	}
	
	@Override
	public Exam loadByName(String name) {
		return examMapper.selectByName(name);
	}

	@Override
	public void delete(User user, Long id) {
		examMapper.delete(id);

	}

	@Override
	public List<Exam> loadAll() {
		List<Exam> ls = examMapper.selectAll();
		if(ls == null)
			ls = new ArrayList<>();
		
		return ls;
	}

	@Override
	public void add(Exam exam) {
		Integer maxNo = examMapper.selectMaxNo();
		if(maxNo == null)
			maxNo = 0;
		
		exam.setNo( maxNo +1 );
		examMapper.insert(exam);
	}

	@Override
	public void update(Exam exam) {
		examMapper.update(exam);
	}

}
